﻿

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    var cookiestring;
    exdate.setDate(exdate.getDate() + expiredays);
    cookiestring = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString()) + ";path=/";
    document.cookie = cookiestring;
    //alert ("setting cookie " + cookiestring);
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function delete_cookie(cookie_name) {
    var cookie_date = new Date();  // current date & time
    var cookiestring;
    cookie_date.setTime(cookie_date.getTime() - 10000000000);
    cookiestring = cookie_name += "=; expires=" + cookie_date.toGMTString() + ";path=/";
    document.cookie = cookiestring;
}

// adds a unique() member function to javascript arrays.
Array.prototype.unique = function () {
    var r = new Array();
    o: for (var i = 0, n = this.length; i < n; i++) {
        for (var x = 0, y = r.length; x < y; x++) {
            if (r[x] == this[i]) {
                continue o;
            }
        }
        r[r.length] = this[i];
    }
    return r;
}
